a = [6,1,2,5,4,3,9,7,10,8]
def quick_sorting():
    global a
    stack = []
    stack.append(len(a)-1)
    stack.append(0)
    while stack:
        left = stack.pop()
        right = stack.pop()
        mid_i = partition(a, left, right)
        if left < mid_i - 1:
            stack.append(mid_i - 1)
            stack.append(left)
        if right > mid_i + 1:
            stack.append(right)
            stack.append(mid_i + 1)


def partition(a, start, end):
    pivot = a[start]
    while start < end:
        while start < end and a[end] >= pivot:
            end -= 1
        a[start] = a[end]
        while start < end and a[start] <= pivot:
            start += 1
        a[end] = a[start]
    a[start] = pivot
    return start

quick_sorting()
print(a)